package org.example.lifecycle;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Component
public class BeanLifeComponent implements BeanNameAware, BeanFactoryAware, ApplicationContextAware {

    public BeanLifeComponent() {
        System.out.println("实例化BeanLifeComponent");
    }

    @PostConstruct
    public void postConstruct() {
        System.out.println("初始化方法 PostConstruct()");
    }
    @PreDestroy
    public void preDestroy() {
        System.out.println("销毁方法：preDestroy()");
    }
    public void setBeanName(String s) {
        System.out.println("Aware[BeanNameAware]：" + s);
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("Aware[BeanFactoryAware]");
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("Aware[ApplicationContextAware]");
    }
}